﻿using HalconDotNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HalconWPF
{
    public static class HDrawingObjectExtension
    {
        /// <summary>
        /// 根据绘制对象生成不同形状
        /// </summary>
        /// <param name="hDrawingObjectInfo"></param>
        /// <returns></returns>
        public static HObject GenHObject(this HDrawingObjectInfo hDrawingObjectInfo)
        {
            HObject hDrawingObject = null;

            switch (hDrawingObjectInfo.Type)
            {
                case "rectangle1":
                    HOperatorSet.GenRectangle1(out hDrawingObject, hDrawingObjectInfo.HTuples[0], hDrawingObjectInfo.HTuples[1],
                        hDrawingObjectInfo.HTuples[2], hDrawingObjectInfo.HTuples[3]);
                    break;
                case "circle":
                    HOperatorSet.GenCircle(out hDrawingObject, hDrawingObjectInfo.HTuples[0], hDrawingObjectInfo.HTuples[1],
                        hDrawingObjectInfo.HTuples[2]);
                    break;
            }

            return hDrawingObject;
        }

        /// <summary>
        /// 根据绘制对象获取参数
        /// 矩形四个参数 
        /// 圆形三个参数 中心点X轴，Y轴，半径
        /// </summary>
        /// <param name="hDrawingObject"></param>
        /// <returns></returns>
        public static HTuple[] GetHTuples(this HDrawingObject hDrawingObject)
        {
            HTuple[] hTuples = null;
            string type = hDrawingObject.GetDrawingObjectParams("type");
            switch (type)
            {   
                case "rectangle1":
                    hTuples = new HTuple[4];
                    hTuples[0] = hDrawingObject.GetDrawingObjectParams("row1");
                    hTuples[1] = hDrawingObject.GetDrawingObjectParams("column1");
                    hTuples[2] = hDrawingObject.GetDrawingObjectParams("row2");
                    hTuples[3] = hDrawingObject.GetDrawingObjectParams("column2");
                    break;
                case "circle":
                    hTuples = new HTuple[3];
                    hTuples[0] = hDrawingObject.GetDrawingObjectParams("row");
                    hTuples[1] = hDrawingObject.GetDrawingObjectParams("column");
                    hTuples[2] = hDrawingObject.GetDrawingObjectParams("radius");
                    break;
            }


            return hTuples;
        }
    }
}
